package com.mlz.mlzmall.ui.utils.mlz;

import android.content.Context;
import android.content.SharedPreferences;

import java.util.Set;

/**
 * Created by Administrator on 2016/4/26.
 */
public class DataSharedPress {

    private SharedPreferences preferences;
    private static DataSharedPress sharedPress;
    private Context context;
    private DataSharedPress(Context context, String fileName){
        this.context = context;
        preferences = context.getSharedPreferences(fileName,Context.MODE_PRIVATE);
    }
    public static DataSharedPress getSharedPress(Context context,String Name){
        if(sharedPress == null){
            sharedPress = new DataSharedPress(context,Name);
        }
        return sharedPress;
    }


    public void putSet(String key,Set value){
        SharedPreferences.Editor editor = preferences.edit();
        editor.putStringSet(key,value);
//        editor.putString(key,value);
        editor.commit();
    }

    public Set getSet(String key){
        return preferences.getStringSet(key,null);
    }
    public void putString(String key,String value){
        SharedPreferences.Editor editor = preferences.edit();
        editor.putString(key,value);
        editor.commit();
    }
    public String getString(String key){
        return preferences.getString(key,"");
    }
    public void putInt(String key,int value){
        SharedPreferences.Editor editor = preferences.edit();
        editor.putInt(key, value);
        editor.commit();
    }
    public int getInt(String key){
        return preferences.getInt(key, -1);
    }
    public void putBoolean(String key,boolean value){
        SharedPreferences.Editor editor = preferences.edit();
        editor.putBoolean(key, value);
        editor.commit();
    }
    public boolean getBoolean(String key){
        return preferences.getBoolean(key,false);
    }

}
